#include "CalculatorDialog.h"

CalculatorDialog::CalculatorDialog (void)
{
	//界面初始化
	setupUi (this);
	//和逻辑相关的代码功能需要自己实现
	m_editX->setValidator (new QDoubleValidator(this));
	m_editY->setValidator (new QDoubleValidator(this));
	//信号与槽的连接
	connect (m_editX, SIGNAL(textChanged(QString)),
			this, SLOT (enableCalcButton()));
	connect (m_editY, SIGNAL(textChanged(QString)),
			this, SLOT (enableCalcButton()));
	connect (m_btnCalc, SIGNAL(clicked()), 
			this, SLOT(calcClicked()));
}
void CalculatorDialog::enableCalcButton ()
{
	bool bXOK, bYOK;
	m_editX->text().toDouble(&bXOK);
	m_editY->text().toDouble(&bYOK);
	m_btnCalc->setEnabled (bXOK && bYOK);
}
void CalculatorDialog::calcClicked ()
{
	double res = m_editX->text().toDouble() + m_editY->text().toDouble();
	QString str = QString::number(res);
	m_editZ->setText (str);
}
